<template>
	<view class="content">
		<view class="body">
			<view class="item">
				<view class="column-css view-cente">
					<view class="row-css view-cente-cle">
						<view class="view-cente-cle-text">版本号</view>
						<view style="padding-right: 30rpx;">{{version}}</view>
					</view>
				</view>
				<view class="column-css view-cente">
					<view class="row-css view-cente-cle" style="justify-content: space-between;align-items: center;border-bottom: none" @click="onLoginout()">
						<view class="row-css" style="flex: 1;justify-content: space-between;">
							<view class="view-cente-cle-text">退出登陆</view>
						</view>
						<image style="width: 28rpx;height: 28rpx;" src="../../static/icon_enter.png"></image>
					</view>
				</view>
	<!-- 	<view class="content_list">
			<view class="header">
				<view class="left">版本号</view>
				<view class="right"><text style="margin: 0 20rpx;">{{version}}</text>
				<image style="width: 28rpx;height: 28rpx;" src="../../static/icon_enter.png"></image>
				</view>
			</view>
			<view class="header" @click="onLoginout()">
				<view class="left">退出登陆</view>
				<view class="right">
					<image style="width: 28rpx;height: 28rpx;" src="../../static/icon_enter.png"></image>
				</view>-->
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				version: '1.0',
				userInfo: {}
			}
		},
		onLoad() {
			let type;
			if (uni.getSystemInfoSync().platform === 'android') {
				type = '0';
			} else {
				type = '1';
			}
			// let openURL = type === '1' ? 'itms-apps://apps.apple.com/cn/app/%E5%A4%96%E8%BF%90%E5%90%AF%E8%88%AA/id1476218508' : 'https://nfp.y2t.com/apk/运必达.apk';
			let openURL = type === '1' ? 'https://apps.apple.com/cn/app/%E8%BF%90%E5%BF%85%E8%BE%BE/id1632128722' :
				'https://nfp.y2t.com/apk/运必达.apk';
			let userPlatform = type === '1' ? 'ios' : 'Android';
			this.version = 'V' + plus.runtime.version;
			this.wxRequest({
				url: `${this.API}/version/check?userVersion=` + this.version + '&userPlatform=' + userPlatform,
				method: 'POST',
				success: res => {
					if (res.data.code == 0) {
						console.log('version', this.version);
						let version = this.version;
						console.log('版本号：' + res.data.data.version);
						if (version != res.data.data.version) {
							if (res.data.data.whether == '1') {
								uni.showModal({
									title: '提示',
									content: '发现有新版本，请立即更新',
									showCancel: false,
									confirmText: '立即更新',
									success: function(res) {
										if (res.confirm) {
											plus.runtime.openURL(openURL);
											plus.runtime.quit();
										}
									}
								});
							} else {
								uni.showModal({
									title: '提示',
									content: '有新版本可升级',
									confirmText: '立即升级',
									cancelText: '稍后升级',
									success: function(res) {
										if (res.confirm) {
											plus.runtime.openURL(openURL);
										} else if (res.cancel) {
											// console.log('用户点击取消');
										}
									}
								});
							}
						}
					}
				}
			});

		},
		onShow: function() {
			this.userInfo = uni.getStorageSync(this.DATA_KEY.userInfo);
			if (this.userInfo.mobile) {
				let driverId = uni.getStorageSync(this.DATA_KEY.userInfo).driverId;
				this.wxRequest({
					url: `${this.API}/driverService/getDriverInfoByDriverID?driver_id=` + this.userInfo
						.driverId + '&etp_id=' + uni.getStorageSync(this.DATA_KEY.etpId),
					method: 'POST',
					title: '加载中...',
					success: res => {
						this.userInfo = res.data.data.userModel;
						uni.setStorageSync(this.DATA_KEY.userInfo, res.data.data.userModel);
						if (
							res.data.data.userModel.etpId != '' &&
							res.data.data.userModel.etpName != '' &&
							!uni.getStorageSync(this.DATA_KEY.etpId) &&
							!uni.getStorageSync(this.DATA_KEY.etpName)
						) {
							uni.setStorageSync(this.DATA_KEY.etpId, res.data.data.userModel.etpId);
							uni.setStorageSync(this.DATA_KEY.etpName, res.data.data.userModel.etpName);
						} else if (res.data.data.userModel.etpId == '' && res.data.data.userModel
							.etpName == '') {
							uni.setStorageSync(this.DATA_KEY.etpId, '');
							uni.setStorageSync(this.DATA_KEY.etpName, '');
						}
					}
				});
			} else if (this.userInfo.captainPhone) {
				this.wxRequest({
					url: `${this.API}/captainApp/captainAuthentication?etpId=${uni.getStorageSync(this.DATA_KEY.etpId)}`,
					method: 'GET',
					success: res => {
						if (res.data.code == 0) {
							if (
								res.data.data.captain.etpId != '' &&
								res.data.data.captain.etpName != '' &&
								!uni.getStorageSync(this.DATA_KEY.etpId) &&
								!uni.getStorageSync(this.DATA_KEY.etpName)
							) {
								uni.setStorageSync(this.DATA_KEY.etpId, res.data.data.captain.etpId);
								uni.setStorageSync(this.DATA_KEY.etpName, res.data.data.captain.etpName);
							} else if (res.data.data.captain.etpId == '' && res.data.data.captain
								.etpName == '') {
								uni.setStorageSync(this.DATA_KEY.etpId, '');
								uni.setStorageSync(this.DATA_KEY.etpName, '');
							}
						}
					}
				});
			}
		},
		methods: {
			onLoginout() {
				var that = this
				if (that.userInfo.mobile || that.userInfo.captainPhone) {
					uni.showModal({
						title: '提示',
						content: '是否退出登录?',
						success: function(res) {
							if (res.confirm) {
								that.wxRequest({
									url: `${that.API}/miniApp/auth/wxLogout`,
									method: 'POST',
									title: '加载中...',
									success: res => {
										uni.setStorageSync(that.DATA_KEY.userInfo, '');
										uni.setStorageSync(that.DATA_KEY.token, '');
										uni.setStorageSync(that.DATA_KEY.etpId, '');
										uni.setStorageSync(that.DATA_KEY.etpName, '');
										uni.setStorageSync(that.DATA_KEY.oldTime, '');
										uni.setStorageSync(that.DATA_KEY.loadingOrderId, '');
										uni.removeStorageSync('loginType');
										uni.switchTab({
											url: '../index/taskhome'
										});
									}
								})
								console.log('确定');
							} else if (res.cancel) {
								console.log('取消');
							}
						}
					});
				}
			}
		}
	}
</script>

<style lang="scss">
page {
	font-size: 30rpx;
	background: #f9f9f9;
}
.body{
	padding: 24rpx;
	.item{
		background: #fff;
		border-radius: 14rpx;
		margin-bottom: 24rpx;
		overflow: hidden;
	}
}
.row-css {
	display: flex;
	flex-direction: row;
}

.column-css {
	display: flex;
	flex-direction: column;
}

.view-cente {
	background: #ffffff;
	padding: 0 30rpx;
}
.view-cente-cle {
	padding: 25rpx 0;
	border-bottom: 1rpx solid #eeeeee;
	justify-content: space-between;
}
.view-cente-cle-text {
	width: 180rpx;
	color: #5f6579;
}
.perfection {
	border-radius: 25rpx;
	padding: 5rpx 10rpx;
	color: #ffffff;
}

</style>
